'use strict';
const dayjs = require('dayjs');
module.exports = app => {
  const { STRING, INTEGER } = app.Sequelize;
    const Play = app.model.define(
      'play',
      {
          id: {type: INTEGER, primaryKey: true, autoIncrement: true},
          member_id: INTEGER(11),
          publish_time: {
              type: app.Sequelize.DATE,
              allowNull: false,
              get() {
                  return dayjs(this.getDataValue('publish_time')).format('YYYY-MM-DD HH:mm:ss');
              },
          },
            remark: STRING(255),
            name: STRING(255),
          active_name: STRING(255),
          active_slogan: STRING(255),
            status: INTEGER(11),
            del_flag: INTEGER(11),
          create_time: {
              type: app.Sequelize.DATE,
              allowNull: false,
              get() {
                  return dayjs(this.getDataValue('create_time')).format('YYYY-MM-DD HH:mm:ss');
              },
          },
          updated_time: {
              type: app.Sequelize.DATE,
              allowNull: false,
              get() {
                  return dayjs(this.getDataValue('updated_time')).format('YYYY-MM-DD HH:mm:ss');
              },
          }
      },
      {
          tableName: 'play',
          timestamps: true, // 启用时间戳(createdAt, updatedAt)
          updatedAt: 'updated_time', // 不想要 updatedAt
          createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 created_at
      }
  );
    Play.associate = function() {
        // 归属一个发起人
        app.model.Play.belongsTo(app.model.Member, { foreignKey: 'member_id', targetKey: 'id' });
    }
    return Play
};
